home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_cmdl.ps < prev    next >
Text File  |  2003-01-03  |  5KB  |  171 lines

  1. %    Copyright (C) 1994, 1996, 1999 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Parse and execute the command line.
  7. % C code handles the following switches: -h/-? -I -M -v
  8.  
  9. /cmddict 50 dict def
  10. cmddict begin
  11.  
  12. % ---------------- Utility procedures ---------------- %
  13.  
  14. % Get the next argument from the parsed argument list.
  15. /nextarg        % - nextarg <arg> true
  16.             % - nextarg false
  17.  { argv length 0 eq
  18.     { false }
  19.     { argv dup 0 get exch dup length 1 sub 1 exch getinterval /argv exch def }
  20.    ifelse
  21.  } bind def
  22.  
  23. % Run a file, under job control if implemented.
  24. /runjob            % <file> runjob -
  25.  { end        % cmddict
  26.    /startjob where { pop false () startjob pop }
  27.    run
  28.    //cmddict begin
  29.  } bind def
  30. /runfilejob        % <filename> runfilejob -
  31.  { findlibfile { exch pop } { (r) file } runjob
  32.  } bind def
  33.  
  34. % Expand arguments.  Free variables: expand@.
  35. /expandarg        % <string> expandarg <args...>
  36.  { dup () eq
  37.     { pop
  38.     }
  39.     { dup dup (--) eq exch (-+) eq or
  40.        { pop /expand@ false def
  41.        }
  42.        { expand@ { (@) anchorsearch } { false } ifelse
  43.       { pop findlibfile
  44.          { exch pop }
  45.          { (r) file }        % let the error happen
  46.         expandargfile
  47.       }
  48.      if
  49.        }
  50.       ifelse
  51.     }
  52.  } bind def
  53. /expandargfile        % <file> expandargfile <args...>
  54.  { [ exch cvlit
  55.     { token not { exit } if
  56.       dup type /stringtype ne { =string cvs dup length string copy } if
  57.       expandarg
  58.     }
  59.    /exec cvx
  60.    ] cvx loop
  61.  } bind def
  62.  
  63. % ---------------- Recognized switches ---------------- %
  64.  
  65. % Switches with arguments are defined as <x>;
  66. % switches without arguments are defined as -<x>.
  67.  
  68. % Switches without arguments
  69. /--
  70.  { nextarg not
  71.     { (-- and -+ require a file name.) = flush }
  72.     { //systemdict /ARGUMENTS argv put /argv [] def runjob }
  73.    ifelse
  74.  } bind def
  75. /-+ /-- load def
  76. /-@ /-- load def
  77. /-A { (@) Z } bind def
  78. /-c
  79.  {  { argv length 0 eq { exit } if
  80.       argv 0 get (-) anchorsearch { pop pop exit } if
  81.       pop nextarg token
  82.        { exch pop            % Probably should check for empty.
  83.      end exec //cmddict begin
  84.        }
  85.       if
  86.     }
  87.    loop
  88.  } bind def
  89. /-e { (#) Z } bind def
  90. /-E /-e load def
  91. /-f { } def
  92. /-q { //systemdict /QUIET true put } bind def
  93.  
  94. % Switches with arguments
  95. /d
  96.  { (=) search not { (#) search not { () exch dup } if } if
  97.    exch pop cvn dup where
  98.     { pop (Redefining ) print print ( is not allowed.) = flush pop }
  99.     { exch token
  100.        { exch pop }        % Probably should check for empty.
  101.        { true }
  102.       ifelse
  103.       //systemdict 3 1 roll put
  104.     }
  105.    ifelse
  106.  } bind def
  107. /D /d load def
  108. /f { dup length 0 ne { runfilejob } if } bind def
  109. /g
  110.  { (x) search { cvi pop exch cvi } { cvi dup } ifelse
  111.    //systemdict begin /DEVICEHEIGHT exch def /DEVICEWIDTH exch def end
  112.  } bind def
  113. /r
  114.  { (x) search { cvr pop exch cvr } { cvr dup } ifelse
  115.    //systemdict begin /DEVICEYRESOLUTION exch def /DEVICEXRESOLUTION exch def end
  116.  } bind def
  117. /s
  118.  { (=) search not { (#) search not { () exch dup } if } if
  119.    exch pop cvn dup where { pop dup load } { () } ifelse
  120.    type /stringtype ne
  121.     { (Redefining ) print print ( is not allowed.) = flush pop }
  122.     { exch //systemdict 3 1 roll put }
  123.    ifelse
  124.  } bind def
  125. /S /s load def
  126. /Z { true .setdebug } bind def
  127.  
  128. % ---------------- Main program ---------------- %
  129.  
  130. % We process the command line in two passes.  In the first pass,
  131. % we read and expand any @-files as necessary.  The second pass
  132. % does the real work.
  133.  
  134. /cmdstart
  135.  { //cmddict begin
  136.    /expand@ true def
  137.    [
  138.         % Process the GS_OPTIONS environment variable.
  139.    (GS_OPTIONS) getenv { 0 () /SubFileDecode filter expandargfile } if
  140.         % Process the actual command line.
  141.    .getargv { expandarg } forall
  142.    ] readonly /argv exch def
  143.         % Now interpret the commands.
  144.     { nextarg not { exit } if
  145.       dup 0 get (-) 0 get eq
  146.        { dup length 1 eq
  147.       { pop (%stdin) (r) file runjob
  148.       }
  149.       { dup length 2 gt
  150.          { dup dup length 2 sub 2 exch getinterval exch 1 1 getinterval }
  151.         if currentdict .knownget
  152.          { exec
  153.          }
  154.          { (Ignoring unknown switch ) print
  155.            dup length 1 eq { (-) print print } if print
  156.            () = flush
  157.          }
  158.         ifelse
  159.       }
  160.      ifelse
  161.        }
  162.        { runfilejob
  163.        }
  164.       ifelse
  165.     }
  166.    loop end
  167.  } bind def
  168.  
  169. end        % cmddict
  170.